<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <base href="#(basePath)"/>
    <title>公告管理 - 公告更新</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/layui/css/layui.css" media="all">
    <script src="/static/ueditor/ueditor.config.js"></script>
    <script src="/static/ueditor/ueditor.all.min.js"></script>
    <style type="text/css">
        .layui-form-label {
            width: 100px;
        }
        .layui-form-select dl {
            z-index: 9999;
        }
    </style>
</head>
<body>

<form class="layui-form layui-form-pane" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">已有类别</label>
        <div class="layui-input-block">
            <select  lay-filter="noticeType" >
                #for(x : noticetype)
                <option value="#(x.type)" #(x.type == noticeinfo.type ? 'selected' : '') >#(x.type)</option>
                #end
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">新的类别</label>
        <div class="layui-input-block">
            <input type="text" id="noticeType_input" name="notice.type" class="layui-input" placeholder="在此输入可添加新类别"
                   lay-verify="required" value="#(noticeinfo.type)"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">标题</label>
        <div class="layui-input-block">
            <input type="text" id="title" name="notice.title" class="layui-input" placeholder="在此输入帮助内容的标题"
                   lay-verify="required" value="#(noticeinfo.title )"/>
        </div>
    </div>

    <div class="layui-form-item layui-form-text" style="height: 500px;width: 100%;">
        <div id="abc" class="layui-input-block" style="height: 500px;width: 100%">
            <textarea id="content" name="content" lay-verify="required">#(noticeinfo.content )</textarea>
            <script type="text/javascript">
                var editor = new UE.ui.Editor({initialFrameHeight: 500, initialFrameWidth: '100%'});
                editor.render("content");
            </script>
        </div>
    </div>


    <div class="layui-form-item layui-hide">
        <input type="input"  name="notice.id" value="#(noticeinfo.id )">
        <input type="input"  name="notice.createtime" value="#(noticeinfo.createtime )">
        <input type="button" lay-submit lay-filter="layuiadmin-app-form-edit" id="layuiadmin-app-form-edit" value="确认编辑">
    </div>
</form>


<script src="/static/layui/layui.js"></script>
<script src="/static/ueditor/initUE.js"></script>
<script>
    layui.config({
        base: '#(basePath)' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form'], function () {
        var $ = layui.$,form = layui.form;

        // 监听下拉框
        form.on('select(noticeType)', function(data){
            $("#noticeType_input").val(data.value);
        });

        //监听提交
        form.on('submit(layuiadmin-app-form-edit)', function (data) {
            var field = data.field; //获取提交的字段
            console.log(field);

            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            //提交 Ajax 成功后，关闭当前弹层并重载表格
            $.ajax({
                url: layui.setter.base + "admin/notice/update",
                type: "post",
                data:field,
                success: function (res) {
                    if (res.code !== 0) {
                        parent.layer.msg(res.msg, {icon: 2});
                    } else {
                        parent.layer.msg("更新成功", {icon: 1});
                        parent.layui.$("#LAY_app_body > div.layui-show iframe").get()[0].contentWindow.layui.table.reload('LAY-web-list'); //重载表格
                        parent.layer.close(index); //再执行关闭
                    }
                },
                error: function (xhr) {
                    parent.layer.msg("出错了" + xhr);
                }
            });
        });
    });

</script>
</body>
</html>
